Skip to content

feat: fetch the tags and push each one individually #195

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 12 commits into from
Apr 1, 2025

Conversation

WeslleyNasRocha
Copy link
Contributor

@WeslleyNasRocha WeslleyNasRocha commented Dec 3, 2024

This is to bypass the limitation of gitlab

Fix #194

Summary by CodeRabbit

  • New Features
    • Enhanced release publishing: Tags are now pushed either individually or collectively based on release context.
    • Improved release creation by more robustly evaluating configuration inputs.
    • Updated publishing workflow to produce compact, clearer output.
    • New constants introduced for managing falsy values and GitLab tag limits.
  • Bug Fixes
    • Resolved TypeScript import issues for better functionality in reading changesets.
  • Chores
    • Updated repository URL in package configuration.

Copy link

changeset-bot bot commented Dec 3, 2024

🦋 Changeset detected

Latest commit: e9ef014

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
changesets-gitlab Minor

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

Copy link

codesandbox-ci bot commented Dec 3, 2024

This pull request is automatically built and testable in CodeSandbox.

To see build info of the built libraries, click here or the icon next to each commit SHA.

@WeslleyNasRocha
Copy link
Contributor Author

I've published a package and tested on our use case,

@rsafonseca
Copy link

@JounQin could you please take a look? 🙏

@JounQin
Copy link
Member

JounQin commented Feb 14, 2025

Sorry I didn't notice this PR previously, just raised some reviews.

Copy link

coderabbitai bot commented Apr 1, 2025

Walkthrough

This pull request adds a new changeset file that describes a minor feature for tag pushing and modifies the behavior of the publishing process. The changes update the evaluation of input flags using a centralized falsy values set, adjust the tag pushing control flow to allow individual tag pushes, and alter export declarations for several entities. Additionally, import statements and configuration details in workflows and package metadata have been updated.

Changes

File(s) Change Summary
.changeset/mighty-chefs-serve.md New changeset file added with metadata and a feature description for fetching and pushing tags based on package count and a feature flag.
src/main.ts, src/utils.ts Updated runPublish to use FALSY_VALUES for evaluating createGitlabReleases; added new constants FALSY_VALUES and GITLAB_MAX_TAGS.
src/run.ts, src/git-utils.ts Modified tag push control flow: introduced pushAllTags decision in run.ts and added an asynchronous pushTag function in git-utils.ts; updated export declarations.
src/read-changeset-state.ts Replaced the workaround import with a direct import of readChangesets from @changesets/read.
.github/workflows/pkg-pr-new.yml, package.json Updated workflow command with the --compact flag; revised the repository URL in package.json.

Sequence Diagram(s)

sequenceDiagram
    participant Runner as Publish Runner
    participant RunModule as run.ts
    participant GitUtils as git-utils.ts
    participant GitLab as GitLab Server

    Runner->>RunModule: runPublish(...)
    RunModule->>RunModule: Determine "pushAllTags" based on package count and feature flag
    alt pushAllTags is true
        RunModule->>GitUtils: pushTags(all tags)
    else pushAllTags is false
        RunModule->>GitUtils: For each package, call pushTag(tag)
    end
    GitUtils->>GitLab: Execute git push command(s)
Loading

Assessment against linked issues

Objective Addressed Explanation
Ensure all pipelines are triggered for each tag when more than 4 changesets are created (#194)

Poem

In coding burrows, I hop with glee,
Tweaking tags where pipelines run free.
Each tag now hops on its own little trail,
No more lost pipelines in a four-tag tale.
Code-bunny smiles and twitches its ear — hooray! 🐇✨

Warning

There were issues while running some tools. Please review the errors and either fix the tool's configuration or disable the tool if it's a critical failure.

🔧 ESLint

If the error stems from missing dependencies, add them to the package.json file. For unrecoverable errors (e.g., due to private dependencies), disable the tool in the CodeRabbit configuration.

src/read-changeset-state.ts

Oops! Something went wrong! :(

ESLint: 9.23.0

Error [ERR_MODULE_NOT_FOUND]: Cannot find package '@1stg/eslint-config' imported from /eslint.config.js
at packageResolve (node:internal/modules/esm/resolve:839:9)
at moduleResolve (node:internal/modules/esm/resolve:908:18)
at defaultResolve (node:internal/modules/esm/resolve:1038:11)
at ModuleLoader.defaultResolve (node:internal/modules/esm/loader:557:12)
at ModuleLoader.resolve (node:internal/modules/esm/loader:525:25)
at ModuleLoader.getModuleJob (node:internal/modules/esm/loader:246:38)
at ModuleJob._link (node:internal/modules/esm/module_job:126:49)

src/git-utils.ts

Oops! Something went wrong! :(

ESLint: 9.23.0

Error [ERR_MODULE_NOT_FOUND]: Cannot find package '@1stg/eslint-config' imported from /eslint.config.js
at packageResolve (node:internal/modules/esm/resolve:839:9)
at moduleResolve (node:internal/modules/esm/resolve:908:18)
at defaultResolve (node:internal/modules/esm/resolve:1038:11)
at ModuleLoader.defaultResolve (node:internal/modules/esm/loader:557:12)
at ModuleLoader.resolve (node:internal/modules/esm/loader:525:25)
at ModuleLoader.getModuleJob (node:internal/modules/esm/loader:246:38)
at ModuleJob._link (node:internal/modules/esm/module_job:126:49)

src/utils.ts

Oops! Something went wrong! :(

ESLint: 9.23.0

Error [ERR_MODULE_NOT_FOUND]: Cannot find package '@1stg/eslint-config' imported from /eslint.config.js
at packageResolve (node:internal/modules/esm/resolve:839:9)
at moduleResolve (node:internal/modules/esm/resolve:908:18)
at defaultResolve (node:internal/modules/esm/resolve:1038:11)
at ModuleLoader.defaultResolve (node:internal/modules/esm/loader:557:12)
at ModuleLoader.resolve (node:internal/modules/esm/loader:525:25)
at ModuleLoader.getModuleJob (node:internal/modules/esm/loader:246:38)
at ModuleJob._link (node:internal/modules/esm/module_job:126:49)

  • 2 others

📜 Recent review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between b681513 and e9ef014.

📒 Files selected for processing (8)
  • .changeset/mighty-chefs-serve.md (1 hunks)
  • .github/workflows/pkg-pr-new.yml (1 hunks)
  • package.json (1 hunks)
  • src/git-utils.ts (1 hunks)
  • src/main.ts (2 hunks)
  • src/read-changeset-state.ts (1 hunks)
  • src/run.ts (6 hunks)
  • src/utils.ts (1 hunks)
✨ Finishing Touches
  • 📝 Generate Docstrings

🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai plan to trigger planning for file edits and PR creation.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 0

🔭 Outside diff range comments (1)
src/run.ts (1)

98-160: 💡 Verification agent

🧩 Analysis chain

Verify the tag format is consistent with changesets behavior.

The implementation assumes tag format is packageName@version, but for certain repository types, changesets might generate different formats. Please ensure consistency with how changesets generates its tags.


🌐 Web query:

How does changesets format its Git tags for single-package vs multi-package repositories?

💡 Result:

Changesets formats Git tags differently depending on whether they're used in single-package or multi-package repositories:

Single-package repositories

  • Tags follow the format vX.Y.Z (e.g., v1.2.3)
  • Includes a "v" prefix before the semantic version[1][2][6]

Multi-package repositories

  • Tags use package-name@X.Y.Z format (e.g., utils@1.0.0)
  • Combines the package name with its version number[2][6][8]
Repository Type Tag Format Example
Single-package v1.2.3
Multi-package (monorepo) my-package@1.0.0

This distinction ensures clear version tracking in monorepos while maintaining conventional version tagging for standalone packages. The tags are automatically generated during the changeset publish command, and Changesets handles dependency-aware versioning in monorepos by:

  1. Updating interdependent package versions when needed[3][6]
  2. Creating separate tags for each modified package[5][10]

For both repository types, you must manually push tags using git push --follow-tags after publishing[2][8]. The version numbers themselves are determined from package.json files, which Changesets updates during the version command[1][6].

Citations:


Action: Align single-package tag format with Changesets behavior

In the single-package branch (tool === 'root'), the current code pushes tags in the format packageName@version (e.g., my-package@1.2.3), while Changesets for single-package repositories generate tags with a v prefix (e.g., v1.2.3). This leads to inconsistency since the GitLab release call correctly uses v${pkg.packageJson.version}. Please update the push tag logic in the single-package branch to use the vX.Y.Z format.

  • Change the tag pushed in the tool === 'root' branch to use v${pkg.packageJson.version}.
  • Verify that the regex and tag-naming logic in the multi-package branch remain correct.
♻️ Duplicate comments (1)
src/run.ts (1)

120-124: 💡 Verification agent

🧩 Analysis chain

Consider using v${pkg.packageJson.version} for single-package repositories.

For single package repositories, the tag should be only vx.y.z format instead of packageName@version.


🏁 Script executed:

#!/bin/bash
# Check if this is a single-package or multi-package repository
# by looking at the package.json files in the repository

echo "Checking repository structure..."
# Count package.json files (excluding node_modules)
PACKAGE_COUNT=$(find . -name "package.json" -not -path "*/node_modules/*" -not -path "*/dist/*" -not -path "*/build/*" | wc -l)
echo "Found $PACKAGE_COUNT package.json files"

# If it's just one, it's likely a single-package repo
if [ "$PACKAGE_COUNT" -eq 1 ]; then
  echo "This appears to be a single-package repository"
  echo "For single-package repos, tag format should be 'vx.y.z' instead of 'packageName@version'"
else
  echo "This appears to be a multi-package repository"
  echo "Current implementation using 'packageName@version' tag format is appropriate"
fi

Length of output: 588


Action Required: Update Tag Format for Single-Package Repository

Our repository verification confirms that there is only one package.json file, indicating a single-package repository. In such cases, the tag generated should follow the v<version> format. Please update the tag in src/run.ts (Lines 120-124) accordingly. For example:

-if (!pushAllTags) {
-  await gitUtils.pushTag(
-    `${pkg.packageJson.name}@${pkg.packageJson.version}`,
-  )
-}
+if (!pushAllTags) {
+  await gitUtils.pushTag(`v${pkg.packageJson.version}`)
+}
🧹 Nitpick comments (1)
src/run.ts (1)

154-160: Use Promise.all for better performance when pushing multiple tags.

When pushing multiple tags, using Promise.all would provide better performance by executing the pushes in parallel rather than sequentially.

if (!pushAllTags) {
-  for (const pkg of releasedPackages) {
-    await gitUtils.pushTag(
-      `${pkg.packageJson.name}@${pkg.packageJson.version}`,
-    )
-  }
+  await Promise.all(
+    releasedPackages.map(pkg => 
+      gitUtils.pushTag(`${pkg.packageJson.name}@${pkg.packageJson.version}`)
+    )
+  )
}
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between e9adb24 and f1eb12c.

📒 Files selected for processing (5)
  • .changeset/mighty-chefs-serve.md (1 hunks)
  • README.md (1 hunks)
  • src/gitUtils.ts (1 hunks)
  • src/main.ts (1 hunks)
  • src/run.ts (5 hunks)
🔇 Additional comments (7)
.changeset/mighty-chefs-serve.md (1)

1-5: LGTM! The changeset file is well-formatted.

The changeset correctly specifies a minor version change for 'changesets-gitlab' with a clear description of the intended change: "fetch the tags and push each one individually".

src/gitUtils.ts (1)

33-35: LGTM! Good addition of a focused utility function.

The pushTag function follows the same pattern as other Git utility functions in this file, maintaining consistency in the codebase.

README.md (1)

34-34: Documentation is clear and well-linked to the issue.

The new input parameter INPUT_PUSH_ALL_TAGS is well-documented with its type, default value, and purpose. Linking to the related issue (#194) provides additional context for users.

src/run.ts (3)

63-63: Interface update looks good.

The PublishOptions interface has been correctly updated to include the new optional boolean parameter pushAllTags.


86-86: Function parameter update is correctly implemented.

The runPublish function correctly includes the new parameter with a default value of true, maintaining backward compatibility.


98-100: Conditional tag pushing is properly implemented.

The logic correctly checks the pushAllTags parameter before pushing all tags at once.

src/main.ts (1)

91-91: Good addition of the tag pushing control parameter.

The new pushAllTags parameter allows for controlling whether to push all tags at once or individually, which directly addresses the GitLab limitation regarding the number of pipelines that can be triggered per Git push (as mentioned in issue #194).

The default behavior is preserved by setting it to true unless explicitly set to 'false', maintaining backward compatibility.

@JounQin JounQin force-pushed the fix/gitlab-pipelines-limitation branch from f1eb12c to f146e08 Compare April 1, 2025 08:22
Copy link

pkg-pr-new bot commented Apr 1, 2025

Open in StackBlitz

npm i https://pkg.pr.new/changesets-gitlab@195

commit: e9ef014

@JounQin
Copy link
Member

JounQin commented Apr 1, 2025

I've published a package and tested on our use case,

Hi @WeslleyNasRocha I'm going to merge and release this PR, is there anything special else other than this PR?

I've changed to detect packages.length + api.FeatureFlags instead, so no input is required.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 0

🧹 Nitpick comments (1)
.github/workflows/pkg-pr-new.yml (1)

30-30: Update publish command with --compact flag

The command now runs as yarn dlx pkg-pr-new publish --compact, which is intended to produce a more concise output during the publish process. Please confirm that:

  • The --compact option is recognized by the pkg-pr-new tool.
  • The behavior of the publishing step (including any tag pushing logic affected by this flag) remains correct as per the new PR objectives.
  • Any documentation updates (e.g., related to INPUT_PUSH_ALL_TAGS and tag handling) are consistent with this change.

Consider running a pipeline test to verify that the new flag does not cause unintended side effects.

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between f146e08 and 44e57a3.

📒 Files selected for processing (1)
  • .github/workflows/pkg-pr-new.yml (1 hunks)
⏰ Context from checks skipped due to timeout of 90000ms (1)
  • GitHub Check: Codacy Static Code Analysis

Copy link

sonarqubecloud bot commented Apr 1, 2025

@JounQin JounQin changed the title fix: fetch the tags and push each one individually feat: fetch the tags and push each one individually Apr 1, 2025
@JounQin
Copy link
Member

JounQin commented Apr 1, 2025

@coderabbitai rull review

@JounQin
Copy link
Member

JounQin commented Apr 1, 2025

@codecov-ai-reviewer review

Copy link

codecov-ai bot commented Apr 1, 2025

On it! We are reviewing the PR and will provide feedback shortly.

Copy link

coderabbitai bot commented Apr 1, 2025

🧩 Analysis chain

I'll conduct a full review of this PR. Let me first gather more information about the code changes.


🏁 Script executed:

#!/bin/bash
# First, examine the issue that this PR is trying to fix
gh issue view 194 --repo un-ts/changesets-gitlab

# Let's look at the changed files in this PR
git diff --name-only HEAD~1 HEAD

# Let's examine the changes in each key file
echo "=== Changes in src/main.ts ==="
git diff HEAD~1 HEAD -- src/main.ts

echo "=== Changes in src/run.ts ==="
git diff HEAD~1 HEAD -- src/run.ts

echo "=== Changes in src/git-utils.ts ==="
git diff HEAD~1 HEAD -- src/git-utils.ts

echo "=== Changes in src/utils.ts ==="
git diff HEAD~1 HEAD -- src/utils.ts

echo "=== Changes in README.md ==="
git diff HEAD~1 HEAD -- README.md

Length of output: 1973


I'll try a different approach to retrieve the PR changes:


🏁 Script executed:

#!/bin/bash
# Show available branches
git branch -a

# Use GitHub CLI to get PR changes
gh pr view 195 --repo un-ts/changesets-gitlab --json files

# Let's look at the actual files in the PR
echo "=== Contents of src/main.ts ==="
cat src/main.ts

echo "=== Contents of src/run.ts ==="
cat src/run.ts

echo "=== Contents of src/git-utils.ts ==="
cat src/git-utils.ts

echo "=== Contents of src/utils.ts ==="
cat src/utils.ts

echo "=== Contents of README.md ==="
cat README.md

# Get the latest commit message to understand the change
git log -n 1 --pretty=format:"%s%n%b"

Length of output: 32150


@JounQin I'll conduct a full review of this PR.


🏁 Script executed:

#!/bin/bash
# Get the full PR diff to see all changes
gh pr diff 195 --repo un-ts/changesets-gitlab

# Check the issue this PR is addressing
gh issue view 194 --repo un-ts/changesets-gitlab

Length of output: 7644


@JounQin I've reviewed PR #195 "fix: fetch the tags and push each one individually" which addresses GitLab's pipeline limitation (issue #194).

Key Changes

  1. Problem being solved: GitLab API has a limitation of only triggering 4 pipelines per git push, which means when using git push --tags with more than 4 tags, only 4 pipelines will be triggered.

  2. Solution implemented:

    • Added a new pushTag function to push individual tags
    • Added GITLAB_MAX_TAGS = 4 constant to define the GitLab limitation
    • Modified tag pushing logic to either:
      • Push all tags at once (when packages ≤ 4 or feature flag is enabled)
      • Push tags individually (when packages > 4 and feature flag is disabled)
  3. Implementation details:

    • Checks package count against GITLAB_MAX_TAGS
    • Tries GitLab feature flag git_push_create_all_pipelines as a fallback
    • Uses Promise.all for parallel tag pushing when needed
  4. Code quality improvements:

    • Added FALSY_VALUES set for consistent boolean checking
    • Fixed TypeScript module import for @changesets/read
    • Added proper exports to interfaces and functions

The changes are well-implemented and focused on solving the specific issue. The author already tested this in their environment with a published package.

✅ Actions performed

Review triggered.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

@JounQin
Copy link
Member

JounQin commented Apr 1, 2025

@coderabbitai summary

Copy link

coderabbitai bot commented Apr 1, 2025

✅ Actions performed

Summary regeneration triggered.

@JounQin
Copy link
Member

JounQin commented Apr 1, 2025

There were issues while running some tools. Please review the errors and either fix the tool's configuration or disable the tool if it's a critical failure.

@coderabbitai Please, don't let me remind you again that you need to run yarn build first before lint.

Copy link

coderabbitai bot commented Apr 1, 2025

Tip

For best results, initiate chat on the files or code changes.

@JounQin I sincerely apologize for the oversight. You're absolutely right - I should always run yarn build before yarn lint for this repository. I've added this to my knowledge base and will ensure I follow this workflow order in future reviews. Thank you for your patience.


✏️ Learnings added
Learnt from: JounQin
URL: https://github.com/un-ts/changesets-gitlab/pull/195

Timestamp: 2025-04-01T09:12:21.672Z
Learning: For the un-ts/changesets-gitlab repository, always run `yarn build` before running `yarn lint` as the build process generates files required by the linting process.

Note: Learnings are effective only in the context of similar code segments. To apply general coding guidelines, please configure review instructions. You can manage existing learnings in the app.

@JounQin JounQin merged commit e7cbdff into un-ts:main Apr 1, 2025
15 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Bug: GitLab API triggers only 4 pipelines per commit push
3 participants